package com.atguigu.mvc.controller;

import com.atguigu.mvc.util.WebUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/test")
public class RequestMappingController {

    //此时请求映射所映射的请求的请求路径为：/test/testRequestMapping
    @RequestMapping(value = {"/testRequestMapping", "/hi", "/hello"}, method = {})
    public String testRequestMapping(HttpServletRequest request) {

        System.out.println("request = " + request);
        System.out.println("请求方法 = " + request.getMethod());
        System.out.println("url = " + request.getRequestURL());
        return "success";
    }


    @RequestMapping(
            value = "/testParamsAndHeaders",
            params = {"username", "password!=123456"},
            headers = {"Host=localhost:8080"}
    )
    public String testParamsAndHeaders() {
        return "success";
    }


    //@RequestMapping("/a?a/testAnt")
    //@RequestMapping("/a*a/testAnt")
    @RequestMapping("/**/testAnt")
    public String testAnt() {
        HttpServletRequest request = WebUtil.getServletRequest();
        System.out.println("request = " + request);
        System.out.println("请求方法 = " + request.getMethod());
        System.out.println("url = " + request.getRequestURL());
        return "success";
    }


    @RequestMapping("/testPath/{id}/{username}")
    public String testPath(@PathVariable("id") Integer id, @PathVariable("username") String username) {
        System.out.println("id:" + id + ",username:" + username);
        HttpServletRequest request = WebUtil.getServletRequest();
        System.out.println("request = " + request);
        System.out.println("请求方法 = " + request.getMethod());
        System.out.println("url = " + request.getRequestURL());
        return "success";
    }

}